//
//  ShellWithdrawRecordCell.m
//  ShellWallert
//
//  Created by lvzhao on 2019/10/1.
//  Copyright © 2019 VV. All rights reserved.
//

#import "ShellWithdrawRecordCell.h"
#import "ShellWallertModel.h"

@interface ShellWithdrawRecordCell()

//数量
@property (nonatomic,strong) UILabel *numberLabel;

//状态
@property (nonatomic,strong) UILabel *statusLabel;

//时间
@property (nonatomic,strong) UILabel *timeLabel;
//连接
@property (nonatomic,strong) UIButton *linkBtn;

//model
@property (nonatomic,strong) ShellWallertModel *wallertModel;
@end

@implementation ShellWithdrawRecordCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}


#pragma mark - setupView
- (void)setupView{
    
    //数量
    [self.contentView addSubview:self.numberLabel];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(self.contentView);
    }];
    
    //状态
    [self.contentView addSubview:self.statusLabel];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(100);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(self.contentView);
    }];

    
    //时间
      [self.contentView addSubview:self.timeLabel];
      [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
          make.centerY.mas_equalTo(self.contentView.mas_centerY);
          make.left.mas_equalTo(200);
          make.width.mas_equalTo(K_SCREENWIDTH - 215 - 15 - 60);
          make.height.mas_equalTo(self.contentView);
      }];

      

      //连接
      [self.contentView addSubview:self.linkBtn];
      [self.linkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
         make.centerY.mas_equalTo(self.contentView.mas_centerY);
         make.left.mas_equalTo(K_SCREENWIDTH - 15 - 60);
         make.right.mas_equalTo(-20);
         make.height.mas_equalTo(self.contentView);
      }];
      @weakify(self);
      [[self.linkBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
          @strongify(self);
          NSString *link = [NSString lz_emptyStr:self.wallertModel.link];
          if(![link hasPrefix:@"http"]){
              link = [NSString stringWithFormat:@"http://%@",link];
          }
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];
      }];
}


#pragma mark - actions

#pragma mark - custool

#pragma mark - get && set
- (void)setModelObject:(id)modelObject{
    ShellWallertModel *wallertModel = modelObject;
    self.wallertModel = wallertModel;
    if(self.indexPath.row % 2 == 0){
        self.backgroundColor = COLOR_BACKGROUND;
    } else {
        self.backgroundColor = UIColorHex(0x031D32);
    }
  
    
    
    NSString *link = [NSString lz_emptyStr:wallertModel.link];
    if(link.length == 0){
        self.linkBtn.hidden = YES;
    } else {
        self.linkBtn.hidden = NO;
    }
    
    NSString *operateAmount = [NSString stringWithFormat:@"-%@",wallertModel.operateAmount].saveDecimal;
    NSInteger status = [wallertModel.status integerValue];
    NSString *statusString = @"";
    switch (status) {
        case 10:
        case 20:
        case 21:
            statusString = LZLocalizedString(@"区块确认中");
            break;
        case 30:
            statusString = LZLocalizedString(@"成功");
        break;
        case 40:
            statusString = LZLocalizedString(@"失败");
        break;
        default:
            break;
    }
    self.numberLabel.text = operateAmount;
    self.statusLabel.text = statusString;
    self.timeLabel.text = wallertModel.createTime;
    
    
}


//货币
- (UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lz_createLabWithTextColor:UIColorHex(0xFFFFFF) font:k_textFont(13)];
    }
    return _numberLabel;
}

//状态
- (UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lz_createLabWithTextColor:UIColorHex(0xFFFFFF) font:k_textFont(13)];
        _statusLabel.numberOfLines = 0;
    }
    return _statusLabel;
}

//时间
- (UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lz_createLabWithTextColor:UIColorHex(0x678DA8) font:k_textFont(13)];
        _timeLabel.numberOfLines = 0;
        [_timeLabel lz_centerAlignment];
    }
    return _timeLabel;
}



//连接
- (UIButton *)linkBtn{
    if (!_linkBtn) {
        _linkBtn = [UIButton lz_buttonTitle:LZLocalizedString(@"查看") titleColor:UIColorHex(0x28C8FE) fontSize:14];
    }
    return _linkBtn;
    
}


@end
